﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="cookies.aspx.cs" Inherits="WebApp.cookies" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> js创建COOKIES</title>
<%-- <script type="text/javascript">
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
//function checkCookie()
//{
//username=getCookie('username')
//username=document .getElementById("TextBox1")
//alert (username .value);
//  
//  }
function checkCookie()
{
username=getCookie('username')
if (username!=null && username!="")
  {
document .getElementById ("TextBox1").value=username 
  }
else 
  {
  var txt=document .getElementById ("TextBox1")
  username=txt.value
  if (username!=null && username!="")
    {
    setCookie('username',username,365)
    }
  }
}
</script>--%>
<%--<script type="text/javascript">

var txt="Hello World!"

document.write("<p>Big: " + txt.big () + "</p>")
document.write("<p>Small: " + txt.small() + "</p>")

document.write("<p>Bold: " + txt.bold() + "</p>")
document.write("<p>Italic: " + txt.italics() + "</p>")

document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>")
document.write("<p>Fixed: " + txt.fixed () + "</p>")
document.write("<p>Strike: " + txt.strike() + "</p>")

document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>")
document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>")

document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>")
document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>")

document.write("<p>Subscript: " + txt.sub() + "</p>")
document.write("<p>Superscript: " + txt.sup() + "</p>")

document.write("<p>Link: " + txt.link("http://www.w3school.com.cn") + "</p>")
</script>--%>
<script type="text/javascript">

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(email,"Email must be filled out!")==false)
    {email.focus();return false}
  }
}
</script>

</head>
<%--<body onload ="checkCookie()">--%>
<body >
<form  runat =server action="cookies.aspx" onsubmit="return validate_form(this)" method="post">>
<div>
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit" > 

<a href="javascript:;" onclick="checkCookie()">111111</a>
    <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
</div>
</form>

</body>
</html>
